package com.nk.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nk.system.beans.ToptenBean;
import com.nk.system.common.search.Search;
import com.nk.system.dao.ProgramStatDao;
import com.nk.system.domain.ProgramStat;
import com.nk.system.service.MainService;

@Service("mainService")
public class MainServiceImpl extends GenericServiceImpl<ProgramStat, String, ProgramStatDao>  implements MainService{

	@Autowired
	public MainServiceImpl(ProgramStatDao programStatDao) {
		super(programStatDao);
	}

	@Override
	public List<ToptenBean> getUname(int type) {
		// TODO Auto-generated method stub
		List<ToptenBean> toptenList = new ArrayList<ToptenBean>();
		
		Search search = new Search(ProgramStat.class);
		
		if(type == 1){
			//Sort int
			search.addSortAsc("countB");
		}
		else if(type == 2){
			//Sort int
			search.addSortAsc("countM");
		}
		else if(type == 3){
			//Sort int
			search.addSortAsc("countD");
		}
		else if(type == 4){
			//Sort int
			search.addSortAsc("count");
		}

		List<ProgramStat> programStatList = dao.search(search);
		
		int num=0;
		for(ProgramStat uniName:programStatList){
			if(num<=10) {
				ToptenBean toptenBean = new ToptenBean(); 
				toptenBean.setUniversity(uniName.getName());
				toptenBean.setNum(uniName.getCountB());
				
				toptenList.add(toptenBean);
				num++;
			}
		}
		
		
		return toptenList;
		
	}



	
	
	
}
